Skip to content

Martina_Rivero_lab_day_2 - #25

Open
Futurartina wants to merge 2 commits into
Ironhack-data-bcn-oct-2023:mainfrom
Futurartina:main
Open

Futurartina wants to merge 2 commits into
Ironhack-data-bcn-oct-2023:mainfrom
Futurartina:main

Conversation

@Futurartina

Copy link
Copy Markdown

No description provided.

@bripollc

Copy link
Copy Markdown

Hola Martina,

Felicidades por tu segundo lab!!!!!!! Nadie dijo que fuera fácil. Te dejo a continuación las correcciones.

Challenge 1

  1. Count the number of elements in tup1 and tup2. Then add the two counts together and check if the sum is the same as the number of elements in tup3.
sum1 = len(tup1)
sum2 = len(tup2)
sum12 = sum1 + sum2
print(sum12)

sum3 = len(tup3)
print(sum3)

En tu código, estas imprimiendo la longitud del tup1 (4) y el tup 2 (4) por separado. Te pide que los sumes, por lo que debes añadir un contador que sume la longitud de ambos tups para que te de 8. Entonces si será igual a la longitud de la tup3, que también es 8.

  1. How many times does each letter in letters appear in tup3?
for i in letters:
    count = 0    
    if i in tup3:
        count +=1
        print("Repeated letter is", i, ",", count, "times")
    else:
            print(" ")

Ojo!!!!!!! Tu código actual lo que está haciendo es incrementar el contador por cada letra que encuentra ya que lo has declarado fuera del bucle. Lo que queremos es que se reinicie cada vez que entra en el bucle por lo que debes añadir el contador dentro del loop.

Challenge 2

  1. Using the pop method, remove the first element from set1.
set1_list = list(set1)
set1_list.pop(0)
set1_list_pop = set(set1_list)  # And we convert it back to a set
print(set1_list_pop)

The pop method removes an element randomly, thus we could convert it to list to pop the first element.

  1. Remove every element in the following list from set1 if they are present in the set. Print the remaining elements.
remaining_elem = []
list_to_remove = [1, 9, 11, 19, 21, 29, 31, 39, 41, 49, 51, 59, 61, 69, 71, 79, 81, 89, 91, 99]

for i in set1:
    if i not in list_to_remove:
        remaining_elem.append(i)
print(remaining_elem)

Challenge 3

  1. Sort the keys of word_freq ascendingly
keys_list = list(word_freq.keys()) #extract the keys from the word_freq dictionary
keys_list.sort()  # sort them alphabetically
print(keys_list)
# Create an empty dictionary word_freq2 
word_freq2 = {}
# Find the corresponding value in word_freq and insert the key-value pair to word_freq2
for key in keys_list:
    word_freq2[key] = word_freq[key]

print(word_freq2)

  1. Sort the values of word_freq ascendingly.
import operator
sorted_tups = sorted(word_freq.items(), key=operator.itemgetter(1))
print(sorted_tups)
word_freq3 = {}

for i in sorted_tups:
    for key,value in word_freq.items():
        if key == i[0]: 
            word_freq3[key] = value

print(word_freq3)

sigue así!!!!!!! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants